package com.qiwo.webshow.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qiwo.common.base.AdminBaseController;
import com.qiwo.webshow.domain.SerisesDO;
import com.qiwo.webshow.service.SerisesService;
import com.qiwo.common.utils.Result;

/**
 * 
 * <pre>
 * 系列类型
 *  @author  chenwenchao
 *  @date 2018-10-23 14:26:54
 * </pre>
 * <small> 2018-10-23 14:26:54 | chenwenchao</small>
 */
@Controller
@RequestMapping("/webshow/serises")
public class SerisesController extends AdminBaseController {
	@Autowired
	private SerisesService serisesService;
	
	@GetMapping()
	@RequiresPermissions("webshow:serises:serises")
	String Serises(){
	    return "webshow/serises/serises";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("webshow:serises:serises")
	public Result<Page<SerisesDO>> list(SerisesDO serisesDTO){
        Wrapper<SerisesDO> wrapper = new EntityWrapper<SerisesDO>().orderBy("sort",true).orderBy("id", false);
        Page<SerisesDO> page = serisesService.selectPage(getPage(SerisesDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("webshow:serises:add")
	String add(){
	    return "webshow/serises/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("webshow:serises:edit")
	String edit(@PathVariable("id") Long id,Model model){
		SerisesDO serises = serisesService.selectById(id);
		model.addAttribute("serises", serises);
	    return "webshow/serises/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("webshow:serises:add")
	public Result<String> save( SerisesDO serises){
		serisesService.insert(serises);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("webshow:serises:edit")
	public Result<String>  update( SerisesDO serises){
		boolean update = serisesService.updateById(serises);
		return update ? Result.ok() : Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("webshow:serises:remove")
	public Result<String>  remove( Long id){
		serisesService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("webshow:serises:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		serisesService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
